package com.atguigu.tingshu.search.receiver;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.search.service.SearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

@Component
public class SearchReceiver {
    @Autowired
    private SearchService searchService;
    @RabbitListener(bindings = @QueueBinding(exchange = @Exchange(value = MqConst.EXCHANGE_ALBUM,durable = "true"),key = MqConst.ROUTING_ALBUM_UPPER,value = @Queue(value = MqConst.QUEUE_ALBUM_UPPER,durable = "true")))
    void listenUpperAlbum(Channel channel, Message message,Long albumId){
        Assert.notNull(albumId,"消息数据传输失败！");
        System.out.println(message);
        System.out.println(message.getBody().toString());
        System.out.println(message.getMessageProperties());
        searchService.upperAlbum(albumId);
    }
    @RabbitListener(bindings = @QueueBinding(exchange = @Exchange(value = MqConst.EXCHANGE_ALBUM,durable = "true"),key = MqConst.ROUTING_ALBUM_LOWER,value = @Queue(value = MqConst.QUEUE_ALBUM_LOWER,durable = "true")))
    void listeLowerAlbum(Channel channel, Message message,Long albumId){
        Assert.notNull(albumId,"消息数据传输失败！");
        System.out.println(albumId);
        searchService.lowerAlbum(albumId);
    }
}
